package org.lt.ttkv.utils;

import androidx.annotation.NonNull;

import java.util.HashMap;

/**
 * @ClassName: KVProvider
 * @Description: 类作用描述
 * @Author: wtl
 * @CreateDate: 2023/7/6 9:51
 * @UpdateUser: 更新者 wtl
 * @UpdateDate: 2023/7/6 9:51
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class KVProvider {
  private static final HashMap<String, Object> keyValueGroup = new HashMap<>();

  @NonNull
  public static <T> T get(Class<?> clazz) {
    try {
      String clazzName = clazz.getName();
      if (keyValueGroup.get(clazzName) != null) {
        return (T) keyValueGroup.get(clazzName);
      }
      Class<T> clazz1 = (Class<T>) Class.forName(clazzName + "Impl");
      T t = clazz1.newInstance();
      keyValueGroup.put(clazzName, t);
      return t;
    } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
      e.printStackTrace();
    }
    return (T) new Object();
  }
}
